package io.persimmon.core.dto.factory;

import io.persimmon.core.dto.Response;
import io.persimmon.core.dto.ResponseCode;
import io.persimmon.core.exception.PersimmonException;

public class ResponseFactory {
    public static <T> Response<T> createSuccess(T t) {
        Response<T> response = new Response<>();
        response.setResponseCode(ResponseCode.SUCCESS.getCode());
        response.setData(t);
        return response;
    }

    public static <T> Response<T> createFail(String message) {
        Response<T> response = new Response<>();
        response.setResponseCode(ResponseCode.FAIL.getCode());
        response.setResponseMessage(message);
        response.setAlertMessage("系统异常");
        return response;
    }

    public static <T> Response<T> createFail(ResponseCode beeResponseCode, String message) {
        Response<T> response = new Response<>();
        response.setResponseCode(beeResponseCode.getCode());
        response.setResponseMessage(message);
        response.setAlertMessage("系统异常");
        return response;
    }

    public static <T> Response<T> createException(PersimmonException beeException) {
        Response<T> response = new Response<>();
        response.setResponseCode(beeException.getRResponseCode().getCode());
        response.setResponseMessage(beeException.getMessage());
        response.setAlertMessage(beeException.getAlertMessage());
        response.setExceptionId(beeException.getId());
        return response;
    }
}
